package com.jason.system.common.util;

import com.jason.system.entity.Remark;
import com.jason.system.entity.Student;
import com.jason.system.entity.Tool;
import com.jason.system.mapper.RemarkMapper;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @version 1.0
 * success come from self-discipline
 * @date 2021/4/10 14:08
 */
@Component
public class StringUtil {

  @Resource
  RemarkMapper remarkMapper;

  private String separate = ",";

  public String stuListToString(List<Student> list){
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i<list.size(); i++){
      stringBuilder.append(list.get(i).getSId());
      if (i<list.size()-1){
        stringBuilder.append(separate);
      }
    }
    return stringBuilder.toString();
  }

  public String toolListToString(List<Tool> list){
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i<list.size(); i++){
      stringBuilder.append(list.get(i).getTId());
      if (i<list.size()-1){
        stringBuilder.append(separate);
      }
    }
    return stringBuilder.toString();
  }

  public  String remarkListToString(List<Remark> list){
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i<list.size(); i++){
      Integer id = remarkMapper.insert(list.get(i));
      stringBuilder.append(id);
      if (i<list.size()-1){
        stringBuilder.append(separate);
      }
    }
    return stringBuilder.toString();
  }

}
